<template>
    <div class="content">
        
        <el-table class="mt20" :data="tableData" border v-loading="form.loading" style="width: 100%;font-size: 16px;" @cell-dblclick="onCellDb">
            <el-table-column type="index" :index="indexMethod" label="序号" width="60" align="center" />
            <el-table-column prop="bill_date" label="清帐日期" show-overflow-tooltip align="center" />
            <el-table-column prop="content" label="描述" show-overflow-tooltip align="center" />
            <el-table-column prop="total_amount" label="金额" show-overflow-tooltip align="center" />
            <el-table-column prop="created_at" label="创建日期" width="180" align="center" />
            <el-table-column prop="status_text" label="状态" width="80" align="center" />
            <el-table-column fixed="right" label="操作" width="150" align="center" >
                <template #default="scope">
                    <el-link type="primary" @click="onEdit(scope.$index)" >编辑</el-link>
                </template>
            </el-table-column>
        </el-table>
        <div class="mt20">
            <el-pagination v-model:current-page="form.current" v-model:page-size="form.limit" :page-sizes="[10, 20, 30, 40, 50, 100]" layout="total, sizes, prev, pager, next, jumper" :total="form.total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
        </div>
    </div>

    <el-dialog v-model="isAuthForm" title="权限管理" width="60%">
        <component :is="authForm" :data = editId :type="2" @onSave="onSave" />
    </el-dialog>
</template>

<script lang="ts" setup>
import { ref,onMounted } from 'vue'
import authForm from './components/authForm.vue';
const indexMethod = (index: number) => {
    return index+= 1
}

const form = ref<any>({search:'',type:2,page:0,current:0,total:10,limit:20,loading:false,parentBorder:false})
const isAuthForm = ref<boolean>(false)
interface Role {
    id: number
    bill_date: string
    content: number
    created_at: string
    status_text: string
    total_amount:number
}
const editId = ref<number>(0)
const tableData = ref<Role[]>([])

const onGetData = () => {
    
}

const onCellDb = (data: Role) => {
    console.log(data)
}

const onEdit = (data: number) => {
    editId.value = 0
    if(data >= 0){
        editId.value = tableData.value[data].id
    }
    isAuthForm.value = true
}

const onSave = () => {
    isAuthForm.value = false
    onGetData()
}

const handleSizeChange = (val: number) => {
    form.value.limit = val
    onGetData()
}
const handleCurrentChange = (val: number) => {
    form.value.page = val
    onGetData()
}
onMounted(()=>{
    onGetData()
})

</script>

<style scoped>

</style>